package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.ImageUtils;
import com.tianqu.tms.core.util.Registry;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.car.actionform.CarPendingLiftActionForm;
import com.tianqu.tms.www.car.viewhelper.CarPendingLiftViewHelper;

/**
 * @author moufeiyu
 * 库存移库中间跳转action
 */
public class CarStockTransferDispatchAction extends TmsAction{
	private Logger logger = Logger.getLogger(CarStockTransferDispatchAction.class);
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		String forward = "";
		CarPendingLiftActionForm registerForm = (CarPendingLiftActionForm) uc.getInputForm();
		CarPendingLiftViewHelper viewhelper = new CarPendingLiftViewHelper();
		viewhelper = (CarPendingLiftViewHelper)uc.getAttribute(VIEWHELP);
		viewhelper.setIsPush(registerForm.getIsPush());
		viewhelper.setToMemberId(registerForm.getMemberId());
		viewhelper.setSerial(registerForm.getSerial());
		viewhelper.setMemberName(registerForm.getMemberName());

		request.setAttribute(VIEWHELP, viewhelper);	
		
		if(StringUtil.isNullOrBlank(registerForm.getAcceptorImage())){

			String[] param = {"受理人照片"};
			setErrorsToRequest(request, TmsConstants.U0005 ,param);
			return mapping.findForward("toConfirm");
		}
		
		
		if("11".equals(registerForm.getSaveInputInfo())){
			String path =ImageUtils.getImageUrl(Registry.getConfig(TmsConstants.UPLOADTMP_CONTEXT_ROOT_KEY));
			viewhelper.setAcceptorImage(path + registerForm.getAcceptorImage());
			forward = "toConfirm";
			
		}else {
			forward = "success";
		}
        uc.setAttribute(TmsConstants.VIEWHELP, viewhelper);		
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(forward);
	}

}
